package win.zxshuo.www.schedule;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import win.zxshuo.www.utils.SystemUtils;

import java.util.concurrent.Executors;

@Configuration
public class ScheduleConfig implements SchedulingConfigurer {

    // 定时器配置，让定时器不再单线程跑，而是多线程跑。但是，如果放在一个方法里还是单线程的，请用的小伙伴知晓。

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {

        taskRegistrar.setScheduler(Executors.newScheduledThreadPool(SystemUtils.getCoreNum()));
    }

}
